<template>
  <div class="main">
    <div class="container">
      <div class="container-top">
        <div class="top">
          <div class="title">学校信息维护</div>
        </div>
        <div class="contentTitle">
          <p>所属学校：<span>{{unitName}}</span></p>
        </div>
      </div>
      <div class="content">
        <el-form
          ref="form"
          :model="form"
          :rules="schoolRules"
          label-width="100px"
        >
          <el-form-item label="学校代码" prop="unit_code">
            <el-input
              v-model="form.unit_code"
              class="common"
              placeholder="单行输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="学校地址" prop="address">
            <el-input
              v-model="form.address"
              class="common"
              placeholder="单行输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系方式" prop="link_phone">
            <el-input
              v-model="form.link_phone"
              class="common"
              placeholder="单行输入"
            ></el-input>
          </el-form-item>
          <el-form-item class="button">
            <el-button
              type="primary"
              @click="onSubmit('form')"
              icon="iconfont icon-baocun_mian"
              class="save"
              >保存</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import { InforMationmaIntenance, InformationmaIndetail, UserInfo } from "@/api/login";
import regular from "@/utils/regular";
export default {
  name: "CreateUser",
  data() {
    return {
      Showbg: false,
      accountValue: "",
      // 所属学校
      unitName: '',
      form: {
        unit_code: "",
        address: "",
        link_phone: "",
      },
      schoolRules: {
        unit_code: [{ validator: regular.validatorCode, trigger: "blur" }],
        address: [
          { validator: regular.validatorAddress, trigger: "blur" },
        ],
        link_phone: [
          { message: "请输入联系方式", trigger: "blur" },
          // { validator: regular.checkMobile, trigger: "blur" },
        ],
      },
      dialogImageUrl: "",
      dialogVisible: false,
      imgUrl:
        "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100",
      fileList: [],
      token: "",
    };
  },
  methods: {
    onSubmit(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.queryInforMationmaIntenance();
        } else {
          return false;
        }
      });
    },
    queryInforMationmaIndetail(){
      InformationmaIndetail({
        token: this.token
      }).then((result)=>{
        // console.log(result);
        const {data} = result;
        this.form = data;
        // console.log(this.form);
      })
    },
    queryInforMationmaIntenance() {
      InforMationmaIntenance({
        token: this.token,
        unit_code: this.form.unit_code,
        address: this.form.address,
        link_phone: this.form.link_phone,
      }).then((result) => {
        if (result.code === 1) {
          this.$message({
            message: "保存成功",
            type: "success",
          });
        } else {
          this.$message({
            message: "保存失败",
            type: "error",
          });
        }
      });
    },
    queryUserInfo(){
      UserInfo({
        token: this.token
      }).then((result)=>{
        const {data} = result;
        this.unitName = data.unit_name
      })
    },
    backgroundShow() {
      this.$emit("backgroundShow", this.Showbg);
    },
  },
  created() {
    this.backgroundShow();
  },
  mounted() {
    const token = sessionStorage.getItem("token");
    this.token = token;
    this.queryUserInfo();
    this.queryInforMationmaIndetail();
  },
};
</script>
<style lang='scss' scoped>
.main {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 0;
  color: #242748;
  margin: 0 auto;
  position: relative;
  font-size: 18px;
  margin: 0 50px 20px 30px;
  text-align: left;
  font-family: "PingFang";
  .container {
    width: 100%;
    height: 925px;
    overflow-y: auto;
    background-color: #fff;
    border-radius: 10px;
    .container-top {
      .top {
        display: flex;
        margin-bottom: 30px;
        .title {
          font-size: 26px;
          font-family: "黑体";
          color: #5673ff;
          margin-right: 60px;
        }
      }
      .contentTitle {
        font-size: 22px;
        color: #242748;
        line-height: 32px;
        p {
          font-weight: 700;
        }
      }
    }
    .container-top {
      padding: 33px 45px 25px;
      border-bottom: solid 1px #e7e9eb;
    }
    .content {
      padding: 40px 40px 0;
      .common {
        width: calc(100% - 40%);
      }
      /deep/.el-input__inner {
        font-size: 18px;
        color: #9d9fa2;
        font-family: "PingFang";
      }
      /deep/.el-input.is-disabled .el-input__inner {
        background-color: #f4f7fc;
      }
      /deep/.el-form-item {
        margin-bottom: 38px;
      }
      /deep/.el-form-item__label {
        text-align: left;
        color: #242748;
        font-size: 18px;
        font-weight: 700;
      }
      /deep/.button .el-form-item__content {
        margin-left: 0 !important;
      }
      // .button {
      //   position: absolute;
      //   bottom: 0;
      // }
      /deep/.el-upload {
        float: left;
      }
      /deep/.el-upload__tip {
        font-size: 18px !important;
        color: #242748 !important;
      }
      /deep/ul.el-upload-list.el-upload-list--picture {
        width: 40%;
      }
      /deep/.el-upload-list--picture .el-upload-list__item {
        height: 70px;
        line-height: 70px;
        background-color: #f4f7fc;
        border: none;
      }
      /deep/.el-upload-list--picture .el-upload-list__item-thumbnail {
        width: 50px;
        height: 50px;
        margin-left: -70px;
      }
      /deep/.el-upload-list--picture
        .el-upload-list__item.is-success
        .el-upload-list__item-name {
        line-height: 48px;
        color: #242748;
        font-size: 14px;
        font-weight: 700;
      }
      .uploadBtn {
        padding: 7px 12px 7px 10px;
        margin-right: 10px;
        background-color: #e5eefe;
        border: solid 1px #c8e3fe;
        color: #2197fd;
        font-size: 14px;
        letter-spacing: 1px;
      }
      /deep/.el-icon-circle-plus {
        color: #2197fd;
        font-size: 16px;
      }
      .preview {
        display: flex;
        align-items: center;
        width: 36%;
        margin-top: 20px;
        padding: 20px 22px;
        background-color: #f4f7fc;
        border-radius: 5px;
        .img {
          width: 30px;
          height: 30px;
          vertical-align: middle;
          img {
            border-radius: 2px;
          }
        }
        .details {
          width: 70%;
          margin: 0 0 0 20px;
          .title {
            width: 90%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            color: #242748;
            font-size: 14px;
            font-weight: 700;
          }
          p {
            line-height: 22px;
            font-size: 12px;
            color: #a1a4b5;
            span {
              margin-right: 10px;
            }
          }
        }
        .preview-btn {
          height: 30px;
          & > div {
            float: left;
            width: 18px;
            height: 18px;
            margin-left: 18px;
          }
          .del {
            width: 16px;
          }
        }
      }
      .save {
        padding: 8px 15px 8px 20px;
        font-size: 14px;
        font-family: "PingFang";
        letter-spacing: 1px;
        margin-right: 10px;
        background-color: #5673ff;
        border: solid 1px #2d4eff;
        box-shadow: 0px 4px 15.52px 0.48px rgba(73, 100, 245, 0.39);
        /deep/i {
          margin-right: 8px;
          font-size: 18px;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>